package com.tool.btn;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.MouseEvent;
import java.util.List;

import javax.swing.SwingConstants;

import org.come.Frame.MsgJframe;
import org.come.Frame.ZhuFrame;
import org.come.Jpanel.ActivityJpanel;
import org.come.Jpanel.ActivityModelJpanel;
import org.come.bean.Coordinates;
import org.come.bean.RoleShow;
import org.come.socket.Agreement;
import org.come.socket.SendMessageUntil;
import org.come.thread.TimeControlRunnable;
import org.come.until.FormsManagement;

import com.tool.image.ImageMixDeal;
import com.tool.imagemonitor.ScriptOpen;
import com.tool.imagemonitor.ScriptTask;
import come.tool.Fighting.FightingMixDeal;
import come.tool.handle.HandleState;
import come.tool.map.XLPath;

public class ActivityBtn extends MoBanBtn {
    private int caozuo;
    private ActivityJpanel activityJpanel;
    private ActivityModelJpanel activityModelJpanel;
    private int subscript;

    public ActivityBtn(String iconpath, int type, int caozuo, int subscript, ActivityJpanel activityJpanel) {
        super(iconpath, type);
        this.caozuo = caozuo;
        this.subscript = subscript;
        this.activityJpanel = activityJpanel;
    }

    public ActivityBtn(String iconpath, int type, Color[] colors, String text, Font font, int caozuo,
                       ActivityModelJpanel activityModelJpanel) {
        super(iconpath, type, colors);
        setText(text);
        setVerticalTextPosition(SwingConstants.CENTER);
        setHorizontalTextPosition(SwingConstants.CENTER);
        setFont(font);
        this.caozuo = caozuo;
        this.activityModelJpanel = activityModelJpanel;
    }

    @Override
    public void chooseyes() {
        // TODO Auto-generated method stub

    }

    @Override
    public void chooseno() {
        // TODO Auto-generated method stub

    }

    @Override
    public void nochoose(MouseEvent e) {
        if (caozuo == 1) {
            String sendmes = Agreement.getAgreement().TaskNAgreement("R2=" + subscript);
            SendMessageUntil.toServer(sendmes);
        } else if (caozuo == 2) {
            if (FightingMixDeal.State != HandleState.USUAL) {return;}
            if (ImageMixDeal.userimg.getTeams()==null) {
                ZhuFrame.getZhuJpanel().addPrompt2("你是队员无法操作");
                return;
            }
            String guide = activityModelJpanel.getActiveBase().getGuide();
            String[] v= guide.split("-");
            if (v.length==5) {
                TimeControlRunnable.addTask(new ScriptTask(v,activityModelJpanel.getActiveBase().getSid()),false);
                return;
            }
            RoleShow roleShow =ImageMixDeal.userimg.getRoleShow();
            Coordinates coordinates = new Coordinates(Integer.parseInt(v[0]), Integer.parseInt(v[1]),Integer.parseInt(v[2]));
            List<Object> list=XLPath.ZDXL(roleShow.getX(), roleShow.getY(), roleShow.getMapid().intValue(),coordinates.getX(),coordinates.getY(), coordinates.getMapID());
            if (list==null) {
                ZhuFrame.getZhuJpanel().addPrompt2("你所在位置无法达到目的地");
                return;
            }
            ScriptOpen open=new ScriptOpen(1);
            open.setNpc(Integer.parseInt(v[3]));
            list.add(0,open);
            TimeControlRunnable.addScript(list);
        }else if (caozuo == 9990) {
            activityJpanel.getActivityWeekJpanel().setVisible(false);
        }else if (caozuo == 9991) {
            activityJpanel.getActivityWeekJpanel().setVisible(true);
        }
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        super.mouseEntered(e);
        if (caozuo == 1) {
            String name = this.getName();
            String vitality = activityJpanel.getLabVitality()[subscript].getText();
            MsgJframe.getJframe().getJapnel().TYC(vitality + "活跃奖励", name);
        } else if (caozuo == 2) {

        }
    }

    @Override
    public void mouseExited(MouseEvent e) {
        super.mouseExited(e);
        if (caozuo == 1) {
            FormsManagement.HideForm(46);// 隐藏窗体
        }
    }

}
